KM.TransformsManager = function()
{
    if ( KM.TransformsManager.caller !== KM.TransformsManager.GetInstance ) {  
        throw new Error("TransformsManager.js, TransformsManager() : This object cannot be instanciated");  
    } 
    
    this._modelViewTransform = new KM.Transform();
    this._ModelViewTransformStack = [];
    this._normalTransform = new KM.Transform();
    this._viewMatrix = mat4.create();
};

KM.TransformsManager.instance = null;

KM.TransformsManager.GetInstance = function()
{
    if( !KM.TransformsManager.instance )
    {
        KM.TransformsManager.instance = new KM.TransformsManager();
    }
    
    return KM.TransformsManager.instance;
};

// constructor
KM.TransformsManager.prototype.constructor = KM.TransformsManager;

KM.TransformsManager.prototype.pushMV = function()
{
    var modelViewTransformCopy = new KM.Transform();
    modelViewTransformCopy.copyFromTransform( this._modelViewTransform );
    
    this._ModelViewTransformStack.push( modelViewTransformCopy );
};

KM.TransformsManager.prototype.popMV = function()
{
    if( this._ModelViewTransformStack.length === 0 )
    {
        throw "TransformsManager.js, popMV() : Can't pop modelView transform !";
    }
    
    this._modelViewTransform = this._ModelViewTransformStack.pop();
};
